From 542355d8bf4522fcdd9cb77eae8e83144d6e3052 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 10 Nov 2015 18:17:23 -0800 Subject: [PATCH] Only read one package from registry tarballs Even if multiple ones are included, don't recurse! Closes #2132 --- src/cargo/sources/path.rs | 15 ++++++++++---- tests/test_cargo_registry.rs | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index eedb88303..fabdc27ae 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -59,12 +59,19 @@ impl<'cfg> PathSource<'cfg> { pub fn read_packages(&self) -> CargoResult> { if self.updated { Ok(self.packages.clone()) - } else if self.id.is_path() && self.id.precise().is_some() { + } else if (self.id.is_path() && self.id.precise().is_some()) || + self.id.is_registry() { // If our source id is a path and it's listed with a precise // version, then it means that we're not allowed to have nested - // dependencies (they've been rewritten to crates.io dependencies) - // In this case we specifically read just one package, not a list of - // packages. + // dependencies (they've been rewritten to crates.io dependencies). + // + // If our source id is a registry dependency then crates are + // published one at a time so we don't recurse as well. Note that + // cargo by default doesn't package up nested dependencies but it + // may do so for custom-crafted tarballs. + // + // In these cases we specifically read just one package, not a list + // of packages. let path = self.path.join("Cargo.toml"); let (pkg, _) = try!(ops::read_package(&path, &self.id, self.config)); diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 3f9fd8511..23be64c55 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -896,3 +896,43 @@ test!(update_multiple_packages { .with_stdout_contains(format!("\ {compiling} foo v0.5.0 ([..])", compiling = COMPILING))); }); + +test!(bundled_crate_in_registry { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + bar = "0.1" + baz = "0.1" + "#) + .file("src/main.rs", "fn main() {}"); + p.build(); + + Package::new("bar", "0.1.0").publish(); + Package::new("baz", "0.1.0") + .dep("bar", "0.1.0") + .file("Cargo.toml", r#" + [package] + name = "baz" + version = "0.1.0" + authors = [] + + [dependencies] + bar = { path = "bar", version = "0.1.0" } + "#) + .file("src/lib.rs", "") + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + "#) + .file("bar/src/lib.rs", "") + .publish(); + + assert_that(p.cargo("run"), execs().with_status(0)); +}); -- 2.30.2